package com.crazy.crazybusinessservice.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crazy.crazybusinessservice.mapper.BankCardBalanceRecordMapper;
import com.crazy.crazybusinessservice.service.BankCardBalanceRecordService;
import com.crazy.crazymodel.model.entity.BankCardWaterRecord;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


@Service
public class BankCardBalanceRecordServiceImpl extends ServiceImpl<BankCardBalanceRecordMapper, BankCardWaterRecord> implements BankCardBalanceRecordService {
    @Override
    public String addRecord(String bankCardId, BigDecimal amount, int type) {

        BankCardWaterRecord waterRecord = new BankCardWaterRecord();

        waterRecord.setBankCardNumber(bankCardId);
        waterRecord.setRecordDate(new Date());
        waterRecord.setType(type);
        waterRecord.setAmount(amount);
        Boolean result =  save(waterRecord);
        if(result){
            return "success";
        }else {
            return "save failed";
        }
    }

    @Override
    public List<BankCardWaterRecord> selectByTime(String bankCardId, Date start, Date end) {
        QueryWrapper<BankCardWaterRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("recordDate",start);
        queryWrapper.le("recordDate",end);
        queryWrapper.eq("bankCardNumber",bankCardId);
        List<BankCardWaterRecord> result = this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<BankCardWaterRecord> selectByTime(String bankCardId, Date start) {
        QueryWrapper<BankCardWaterRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("recordDate",start);
        queryWrapper.eq("bankCardNumber",bankCardId);
        List<BankCardWaterRecord> result = this.baseMapper.selectList(queryWrapper);
        return result;
    }


}
